﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ClarizenGadget.Models;
using Logic;
using Logic.ClarizenObjects;

namespace ClarizenGadget.Controllers
{
    public class RequestController : Controller
    {
        public ActionResult Create()
        {
            var model = new CreateRisk
            {
                Importance = new QueryComponent().GetListByTypeName("Severity", useCache: true).Select(ge => new Severity(ge)),
            };

            return View(model);
        }
        [HttpPost]
        [ValidateInput(false)]
        public ActionResult Create(EnhancementRequest Request)
        {
            try
            {
                var r = Request.ToGenericEntity();
                new QueryComponent().CreateEntity(r);
                return Json(new GadgetResponse<EnhancementRequest> { Data = Request, Status = GadgetResponseStatus.Success });
            }
            catch (Exception e)
            {
                return Json(new GadgetResponse<Task> { Status = GadgetResponseStatus.Error, ErrorMessage = e.Message });
            }
        }
    }
}
